package com.lori.netshop.service;

import java.util.Iterator;
import java.util.List;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lori.netshop.mapper.TbItemMapper;
import com.lori.netshop.pojo.TbItem;
import com.lori.netshop.pojo.TbItemExample;

public class PageTest {
	public static void main(String[] args) {
		//获得IOC容器
		ClassPathXmlApplicationContext cpxac = new ClassPathXmlApplicationContext("classpath:spring/applicationContext-dao.xml");
		//获得mapper接口的代理对象，相当于dao
		TbItemMapper bean = cpxac.getBean(TbItemMapper.class);
		TbItemExample tie = new TbItemExample();
		//开始分页
		PageHelper.startPage(1, 20);
		//执行sql
		List<TbItem> TbItemlist = bean.selectByExample(tie);
		for(TbItem tbItem:TbItemlist){
			System.out.println(tbItem.getTitle());
		}
		//获得分页信息
		PageInfo<TbItem> pageinfo = new PageInfo<TbItem>(TbItemlist);
		System.out.println("总页数为："+pageinfo.getTotal());
	
	
	}
}
